package Logger;

import java.util.logging.Level;
import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;


public class AppLogger 
{
	//***************************************Class Variables*******************************************//

	
	private static Logger logger = null;

	
	//***************************************Constructors*******************************************//

	
	private AppLogger()
	{
	}
	
	
	//***************************************Public Methods*******************************************//


	public static void write(Level level, String msg)
	{
		if(logger == null)
		{
			initiateLogger();
		}
		
		logger.log(level,msg);
	}
	
	
	static public void setLevel(Level level)
	{
		if(logger == null)
		{
			initiateLogger();
		}
		
		logger.setLevel(level);
	}
	
	
	//***************************************Private Methods*******************************************//
	
	
	private static void initiateLogger()
	{
		logger = Logger.getLogger("AppLog");
		FileHandler fh;

		try 
		{
			// This block configure the logger with handler and formatter
			fh = new FileHandler("AppLog.log", true);
			logger.addHandler(fh);
			logger.setLevel(Level.ALL);
			SimpleFormatter formatter = new SimpleFormatter();
			fh.setFormatter(formatter);
		} 
		catch (SecurityException e) 
		{
			e.printStackTrace();
		} 
		catch (IOException e) 
		{
			e.printStackTrace();
		}
	}

}
